<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

final class CreateNoteRecordTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('note_record', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '需求变更记录表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('update_text', 'text', ['null' => true, 'limit' => MysqlAdapter::TEXT_LONG, 'comment' => '变更内容'])
            ->addColumn('update_json', 'json', ['null' => true, 'comment' => 'json字段，存储自定义字段'])
            ->addColumn('note_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '需求ID'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addColumn('created', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('updated', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '更新时间']);

        // 添加索引
        $table->addIndex(['note_id'], ['type' => 'normal', 'name' => 'idx_note_id']);
        // 创建表
        $table->create();

    }

    public function down()
    {
        $this->table('note_record')->drop()->save();
    }
}
